package com.whp.yky.yky.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.whp.yky.yky.entity.poentity.Document;
import com.whp.yky.yky.entity.Process;
import com.whp.yky.yky.response.ResponseData;
import com.whp.yky.yky.service.impl.ProcessServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author whp
 * @since 2021-03-08
 */
@RestController
@CrossOrigin
public class ProcessController {

    @Autowired
    private ProcessServiceImpl processService;

    @PostMapping("/getSProcessInfo")
    public ResponseData getSProcessInfo(@RequestBody Process process, @RequestParam Integer pageNum, @RequestParam Integer pageSize){

        ResponseData res = new ResponseData();
        res.setCode(20000);
        IPage<Process> pageList = processService.getSProcessInfo(new Page( (long)pageNum,(long)pageSize),process);
        res.setData(pageList);
//        res.setTotal(documentServiceImpl.getDocumentInfo(document).size());

        return res;

    }




    @PostMapping("/getZProcessInfo")
    public ResponseData getZProcessInfo(@RequestBody Process process, @RequestParam Integer pageNum, @RequestParam Integer pageSize){

        ResponseData res = new ResponseData();
        res.setCode(20000);
        IPage<Process> pageList = processService.getZProcessInfo(new Page( (long)pageNum,(long)pageSize),process);
        res.setData(pageList);
//        res.setTotal(documentServiceImpl.getDocumentInfo(document).size());

        return res;

    }


    @PostMapping("/getGProcessInfo")
    public ResponseData getGProcessInfo(@RequestBody Process process, @RequestParam Integer pageNum, @RequestParam Integer pageSize){

        ResponseData res = new ResponseData();
        res.setCode(20000);
        IPage<Process> pageList = processService.getGProcessInfo(new Page( (long)pageNum,(long)pageSize),process);
        res.setData(pageList);
//        res.setTotal(documentServiceImpl.getDocumentInfo(document).size());

        return res;

    }

    @PostMapping("/getAlllProcessInfo")
    public ResponseData getAlllProcessInfo(@RequestBody Process process, @RequestParam Integer pageNum, @RequestParam Integer pageSize){

        ResponseData res = new ResponseData();
        res.setCode(20000);
        IPage<Process> pageList = processService.getAlllProcessInfo(new Page( (long)pageNum,(long)pageSize),process);
        res.setData(pageList);
//        res.setTotal(documentServiceImpl.getDocumentInfo(document).size());

        return res;

    }

    @PostMapping("/getAdminProcessInfo")
    public ResponseData getAdminProcessInfo(@RequestBody Process process, @RequestParam Integer pageNum, @RequestParam Integer pageSize){

        ResponseData res = new ResponseData();
        res.setCode(20000);
        IPage<Process> pageList = processService.getAlllProcessInfo(new Page( (long)pageNum,(long)pageSize),process);
        res.setData(pageList);
//        res.setTotal(documentServiceImpl.getDocumentInfo(document).size());

        return res;

    }

    @DeleteMapping("/deletProcessByID/{id}")
    @ApiOperation(value="删除用户", notes="根据id删除用户")
    public ResponseData deletProcessByID(@PathVariable("id") int id){
        ResponseData res = new ResponseData();
        boolean result = processService.removeById(id);

        if (result){
            res.setCode(20000);
            res.setData("success");

        }else{
            res.setCode(50000);
            res.setData("fail");
        }
        return res;
    }



}

